package com.vdong.trade.trading.common.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @author <a href="mailto:clf@vdongzc.com">clf</a>
 * @Description:DateUtil 时间工具类
 * @Date Create on 2018-12-13 15:10:22
 * @since version1.0
 */
public class DateUtil {

    public static final String yyyyMMddHHmm = "yyyyMMddHHmm";

    /*private ThreadLocal<SimpleDateFormat> threadLocal = new ThreadLocal<SimpleDateFormat>() {
        @Override
        protected SimpleDateFormat initialValue() {
            return super.initialValue();
        }
    };*/


    /**
     * 获取月的第一天,时分秒为0(如:2018-12-01 00:00:00)
     * a =0 当月 a = 1 下个月
     *
     * @return
     */
    public static Date getMonthFirstDate(int a) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, a);
        //设置为1号,当前日期既为本月第一天
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        // 时
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        // 分
        calendar.set(Calendar.MINUTE, 0);
        // 秒
        calendar.set(Calendar.SECOND, 0);
        // 毫秒
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static String getDateTimeStr(String pattern) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        LocalDateTime now = LocalDateTime.now();
        return dateTimeFormatter.format(now);
    }


}
